InStr (str1, str2), InStr (start, str1, str2)
Basic and Crystal syntax.
Arguments
- start is the character in str1 where the search is to begin. This is a 1 based index. (This argument is optional.)
- str1 is the text string to be searched.
- str2 is the text string being sought.
Returns
Whole Number
Action
The InStr function returns the position of the first occurrence of one string within another. This position is a 1 based index of the characters in str1. If str2 is not found in str1, the InStr function returns 0. The start argument sets the starting position for the search.
Typical uses
Use this function to determine if one string contains another.
Examples
The following examples are applicable to both Basic and Crystal syntax:
InStr("abcdefg", "bcd")
Returns 2.
InStr(3, "abcdefg", "cde")
Returns 3.
Comments
- This function is designed to work like the Visual Basic function of the same name.
- There are two versions of this function. The first does not use the start argument, the second does. If the start argument is not used, InStr searches all of str1 to try to find str2. If the start argument is used, InStr begins searching at the character in str2 indicated by the start argument.